#include "Tile.h"
#include "Level.h"

Tile::Tile()
{

}

bool Tile::block() const
{
	return true;
}

sf::Vector2f Tile::getPosition() const
{
    return m_skin.getPosition();
}

std::string Tile::getName() const
{
    return m_name;
}

int Tile::getShadow() const
{
    return m_alphaShadow;
}

void Tile::init(const sf::Vector2f position, ImgMgr *imageManager, Level *level)
{
    m_alphaShadow = 0;
    m_shadow.setFillColor(sf::Color::Color(0, 0, 0, 0));
    m_shadow.setSize(sf::Vector2f(32, 32));
    m_shadow.setPosition(position);
    if(level->getTile((getPosition().x + 16) / 32, (getPosition().y + 16) / 32 - 1, 1) != NULL)
    {
        if(level->getTile((getPosition().x + 16) / 32, (getPosition().y + 16) / 32 - 1, 1)->getShadow() == 0)
        {
            m_alphaShadow = 50;
            m_shadow.setFillColor(sf::Color::Color(0, 0, 0, 50));
        }
        else if(level->getTile((getPosition().x + 16) / 32, (getPosition().y + 16) / 32 - 1, 1)->getShadow() == 50)
        {
            m_alphaShadow = 125;
            m_shadow.setFillColor(sf::Color::Color(0, 0, 0, 125));
        }
        else if(level->getTile((getPosition().x + 16) / 32, (getPosition().y + 16) / 32 - 1, 1)->getShadow() == 125)
        {
            m_alphaShadow = 175;
            m_shadow.setFillColor(sf::Color::Color(0, 0, 0, 175));
        }
        else if(level->getTile((getPosition().x + 16) / 32, (getPosition().y + 16) / 32 - 1, 1)->getShadow() == 175)
        {
            m_alphaShadow = 255;
            m_shadow.setFillColor(sf::Color::Color(0, 0, 0, 255));
        }
        else
        {
            m_alphaShadow = 255;
            m_shadow.setFillColor(sf::Color::Color(0, 0, 0, 255));
        }
    }
}

sf::Sprite& Tile::getSprite()
{
    return m_skin;
}

void Tile::tick(Player *player, Level *level)
{

}

void Tile::render(sf::RenderWindow *app)
{
	app->draw(m_skin);
	app->draw(m_shadow);
}
